<?php
 
function fund_basic_information_page()
{
	$html = array("#markup" => "");
	if(user_access("fund_basic_information list"))
	{
		drupal_goto("fund_basic_information/list");
	}
	else if (user_access("fund_basic_information create")){
		global $user;
		$query = "SELECT id FROM {fund_basic_information} WHERE user_id = ?";
		$query_result = db_query($query,array($user->uid));
		$result_values = '';
		$id = "";
		foreach ($query_result as $result_values ) {
			$id = $result_values->id;
		}
		if ($id != '')
		{
			$view_form = drupal_get_form("fund_basic_information_view_form",$id);
			$html["#markup"] .= l("编辑","fund_basic_information/edit/".$id).'&nbsp;&nbsp;';
			$html["#markup"] .= l("管理机构信息管理","fund_manager_intro/view/".$id).'&nbsp;&nbsp;';
			$options = array(
			'target_id' => 'printable',
			'value' => t('打印'),
			'type' => 'link');
			$html["#markup"] .= area_print_form($options);
			$html["#markup"] .= drupal_render($view_form);
			return $html;

		}
		else {
			$html["#markup"] = l("现在没有基金管理机构信息，请进行填写！","fund_basic_information/create");
		}
	}
	else{
		$html["#markup"] = "您没有权限！";
	}
	return $html;
}

//function fund_basic_information_create_page($fund_id)
function fund_basic_information_create_page()
{
	$html = array("#markup" => "");
	//$create_form = drupal_get_form("fund_basic_information_create_form",$fund_id);
	$create_form = drupal_get_form("fund_basic_information_create_form");
	$html["#markup"] .= drupal_render($create_form);
	return $html;
}

//function fund_basic_information_confirm_page($fund_id)
function fund_basic_information_confirm_page()
{
	$html = array("#markup" => "");
	//$confirm_form = drupal_get_form("fund_basic_information_confirm_form",$fund_id);
	$confirm_form = drupal_get_form("fund_basic_information_confirm_form");
	$html["#markup"] .= drupal_render($confirm_form);
	return $html;
}

function fund_basic_information_view_page($perid)
{
	$html = array("#markup" => "");
	$query = "SELECT id FROM " .
           "{fund_basic_information} where id = ?";
  $queryResult = db_query($query, array($perid));
  $ifempty =TRUE;
  foreach ($queryResult as $links ) {
	  if($links->id>0)
		  $ifempty = FALSE;
  }
  if($ifempty)
	 {
	 	 drupal_goto("fund_basic_information");
	 }
	$view_form = drupal_get_form("fund_basic_information_view_form",$perid);
	if(user_access("fund_basic_information list")){
		$html["#markup"] .= l("返回列表","fund_basic_information/list").'&nbsp;&nbsp;';
	}
	//$html["#markup"] .= l("编辑","fund_basic_information/edit/".$perid).'&nbsp;&nbsp;';
	//$html["#markup"] .= l("管理机构信息管理","fund_manager_intro/view/".$perid).'&nbsp;&nbsp;';
	$options = array(
	'target_id' => 'printable',
	'value' => t('打印'),
	'type' => 'link');
	$html["#markup"] .= area_print_form($options);
	$html["#markup"] .= drupal_render($view_form);
	return $html;

}

function fund_basic_information_edit_page($perid)
{
	
	$html = array("#markup" => "");
	$query = "SELECT id FROM " .
           "{fund_basic_information} where id = ?";
  $queryResult = db_query($query, array($perid));
  $ifempty =TRUE;
  foreach ($queryResult as $links ) {
	  if($links->id>0)
		  $ifempty = FALSE;
  }
  if($ifempty)
	 {
	 	 drupal_goto("fund_basic_information");
	 }
		$html["#markup"] .= l("浏览","fund_basic_information/view/".$perid).'<br><br>';
		$edit_form = drupal_get_form("fund_basic_information_edit_form",$perid);
		$html["#markup"] .= drupal_render($edit_form);
		return $html;

}

function fund_basic_information_list_page()
{
	$html = array("#markup" => "");
	$header = array(
	array("data" => "基金名称", "field" => "registered_name"),
	array("data" => "注册时间", "field" => "registration_date"),
	array("data" => "注册资本", "field" => "registered_capital"),
	array("data" => "基金详情","field" => "detail"),
	//array("data" => "基金管理人管理","field" => "set"),
	//array("data" => "对应基金选择","field" => "choose"),
	);
	$query = db_select("fund_basic_information","n")
	->extend("PagerDefault")
	->limit(10)
	->extend("TableSort")
	->orderByHeader($header)
	->fields("n", array(
	"id",
	"registered_name",
	"registration_date",
	"registered_capital",
	));
	$results = $query->execute();
	$rows = array();
	foreach ($results as $node) {
		$rows[] = array(
		"data" => array(
		$node->registered_name,
        format_date($node->registration_date,"custom","Y-m-d"),
		$node->registered_capital,
		l("详情","fund_basic_information/view/".$node->id),
		//l("基金管理人管理","fund_manager_intro/view/".$node->id),
		//l("对应基金选择","fund_basic_information/fund_choose/".$node->id),
		));
	}
	$html["#markup"] .= theme("table",
	array(
		"header" => $header,
		"rows" => $rows,
		"sticky" => TRUE,
		"empty" => "没有记录",
	));
	$html["#markup"] .= theme("pager",
	array(
		"tags" => array()
	));
	return $html;
}

//function fund_basic_information_create_form($form,&$form_state,$fund_id)
function fund_basic_information_create_form($form,&$form_state)
{
	drupal_add_css(drupal_get_path("module","fund_basic_information")."/rkrz_form.css");
	 
	$form["short_name"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<table border=\"1\"><tr><th>基金简称</th><td>",
		"#suffix" => "</td>",
		//'#required' => False,
		"#default_value" => isset($_SESSION["fund_basic_information_form"]["short_name"])? $_SESSION["fund_basic_information_form"]["short_name"]:"",
	);
	$form["registered_name"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>基金注册名称</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["registered_name"])? $_SESSION["fund_basic_information_form"]["registered_name"]:"",
	);
	$form["area"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>所属地区</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["area"])? $_SESSION["fund_basic_information_form"]["area"]:"",
	);
	$form["registered_capital"] = array(
		"#type" => "textfield",	
		"#prefix" => "<tr><th>注册资本(万元)</th><td>",
		"#suffix" => "</td>",
		'#required' => TRUE,
		"#default_value" => isset($_SESSION["fund_basic_information_form"]["registered_capital"])? $_SESSION["fund_basic_information_form"]["registered_capital"]:1,
	);
	$form["contributed_capital"] = array(
		"#type" => "textfield",
		"#prefix" => "<th>当前实缴资本(万元)</th><td>",
		"#suffix" => "</td></tr>",
		'#required' => TRUE,
		"#default_value" => isset($_SESSION["fund_basic_information_form"]["contributed_capital"])? $_SESSION["fund_basic_information_form"]["contributed_capital"]:1,
	);
	$form["offical_reference_number"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>批复文号</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["offical_reference_number"])? $_SESSION["fund_basic_information_form"]["offical_reference_number"]:"",
	);
	$today = getdate();
	$form["officaled_date"] = array(
		"#type" => "date",
		
		"#prefix" => "<th>批复时间</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["officaled_date"])? $_SESSION["fund_basic_information_form"]["officaled_date"]:array("year"=>$today["year"],"month"=>$today["month"],"day"=>$today["mday"]),
	);
			
	$form["organization_form"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>组织形式</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["organization_form"])? $_SESSION["fund_basic_information_form"]["organization_form"]:"",
	);
	$form["organization_number"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>组织机构代码</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["organization_number"])? $_SESSION["fund_basic_information_form"]["organization_number"]:"",
	);
	$today = getdate();
	$form["registration_date"] = array(
		"#type" => "date",
		
		"#prefix" => "<tr><th>注册时间</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["registration_date"])? $_SESSION["fund_basic_information_form"]["registration_date"]:array("year"=>$today["year"],"month"=>$today["month"],"day"=>$today["mday"]),
	);
			
	$form["registration_address"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>注册地址</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["registration_address"])? $_SESSION["fund_basic_information_form"]["registration_address"]:"",
	);
	$form["office_address"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>办公地址</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["office_address"])? $_SESSION["fund_basic_information_form"]["office_address"]:"",
	);
	$form["postcode"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>邮编</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["postcode"])? $_SESSION["fund_basic_information_form"]["postcode"]:"",
	);
	$form["corporate_representative"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>法人代表</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["corporate_representative"])? $_SESSION["fund_basic_information_form"]["corporate_representative"]:"",
	);
	$form["scope_of_business"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>经营范围</th><td  colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["scope_of_business"])? $_SESSION["fund_basic_information_form"]["scope_of_business"]:"",
	);
	$form["contact"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>联系人</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["contact"])? $_SESSION["fund_basic_information_form"]["contact"]:"",
	);
	$form["contact_phone"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>联系人电话</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["contact_phone"])? $_SESSION["fund_basic_information_form"]["contact_phone"]:"",
	);
	$form["contact_cellphone"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>联系人手机</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["contact_cellphone"])? $_SESSION["fund_basic_information_form"]["contact_cellphone"]:"",
	);
	$form["contact_fax"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>联系人传真</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["contact_fax"])? $_SESSION["fund_basic_information_form"]["contact_fax"]:"",
	);
	$form["contact_email"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>联系人邮箱</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["contact_email"])? $_SESSION["fund_basic_information_form"]["contact_email"]:"",
	);
	$form["national_financial_management_organization"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>国家财政资金受托管理机构</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["national_financial_management_organization"])? $_SESSION["fund_basic_information_form"]["national_financial_management_organization"]:"",
	);
	$form["nfmo_address"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>地址</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["nfmo_address"])? $_SESSION["fund_basic_information_form"]["nfmo_address"]:"",
	);
	$form["nfmo_registered_capital"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>注册资本</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["nfmo_registered_capital"])? $_SESSION["fund_basic_information_form"]["nfmo_registered_capital"]:0,
	);
	$form["nfmo_contact"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>联系人</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["nfmo_contact"])? $_SESSION["fund_basic_information_form"]["nfmo_contact"]:"",
	);
	$form["nfmo_contact_phone"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>联系人电话</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["nfmo_contact_phone"])? $_SESSION["fund_basic_information_form"]["nfmo_contact_phone"]:"",
	);
	$form["nfmo_contact_cellphone"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>联系人手机</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["nfmo_contact_cellphone"])? $_SESSION["fund_basic_information_form"]["nfmo_contact_cellphone"]:"",
	);
	$form["nfmo_contact_email"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>联系人邮箱</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["nfmo_contact_email"])? $_SESSION["fund_basic_information_form"]["nfmo_contact_email"]:"",
	);
	$form["province_financial_management_organization"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>省级财政资金受托机构</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["province_financial_management_organization"])? $_SESSION["fund_basic_information_form"]["province_financial_management_organization"]:"",
	);
	$form["pfmo_address"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>地址</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["pfmo_address"])? $_SESSION["fund_basic_information_form"]["pfmo_address"]:"",
	);
	$form["pfmo_registered_capital"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>注册资本</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["pfmo_registered_capital"])? $_SESSION["fund_basic_information_form"]["pfmo_registered_capital"]:0,
	);
	$form["pfmo_contact"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>联系人</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["pfmo_contact"])? $_SESSION["fund_basic_information_form"]["pfmo_contact"]:"",
	);
	$form["pfmo_contact_phone"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>联系人电话</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["pfmo_contact_phone"])? $_SESSION["fund_basic_information_form"]["pfmo_contact_phone"]:"",
	);
	$form["pfmo_contact_cellphone"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>联系人手机</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["pfmo_contact_cellphone"])? $_SESSION["fund_basic_information_form"]["pfmo_contact_cellphone"]:"",
	);
	$form["custodian_bank"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>托管银行</th><td >",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["custodian_bank"])? $_SESSION["fund_basic_information_form"]["custodian_bank"]:"",
	);
	$form["bank_of_deposit"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>开户行</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["bank_of_deposit"])? $_SESSION["fund_basic_information_form"]["bank_of_deposit"]:"",
	);
	$form["bank_contact"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>托管银行联系人</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["bank_contact"])? $_SESSION["fund_basic_information_form"]["bank_contact"]:"",
	);
	$form["bank_contact_cellphone"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>联系人手机</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["bank_contact_cellphone"])? $_SESSION["fund_basic_information_form"]["bank_contact_cellphone"]:"",
	);
	$form["bank_contact_phone"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>联系人电话</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["bank_contact_phone"])? $_SESSION["fund_basic_information_form"]["bank_contact_phone"]:"",
	);
	$form["bank_contact_email"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>联系人邮箱</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["bank_contact_email"])? $_SESSION["fund_basic_information_form"]["bank_contact_email"]:"",
	);
	$form["director_list"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>公司董事名单</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["director_list"])? $_SESSION["fund_basic_information_form"]["director_list"]:"",
	);
	$form["supervisor_list"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>公司监事名单</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["supervisor_list"])? $_SESSION["fund_basic_information_form"]["supervisor_list"]:"",
	);
	$form["investment_field"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>投资产业领域</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["investment_field"])? $_SESSION["fund_basic_information_form"]["investment_field"]:"",
	);
	$form["agree_industry_field"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对产业领域的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["agree_industry_field"])? $_SESSION["fund_basic_information_form"]["agree_industry_field"]:"",
	);
	$form["agree_investment_phase"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对投资阶段的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["agree_investment_phase"])? $_SESSION["fund_basic_information_form"]["agree_investment_phase"]:"",
	);
	$form["agree_investment_region"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对投资地域的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["agree_investment_region"])? $_SESSION["fund_basic_information_form"]["agree_investment_region"]:"",
	);
	$form["agree_management_cost"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对管理费用的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["agree_management_cost"])? $_SESSION["fund_basic_information_form"]["agree_management_cost"]:"",
	);
	$form["agree_effectiveness_reward"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对效益奖励的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["agree_effectiveness_reward"])? $_SESSION["fund_basic_information_form"]["agree_effectiveness_reward"]:"",
	);
	$form["agree_contribute_time_percentage"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对出资时间和出资比例的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["agree_contribute_time_percentage"])? $_SESSION["fund_basic_information_form"]["agree_contribute_time_percentage"]:"",
	);
	$form["agree_fund_duration"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对基金存续期的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["agree_fund_duration"])? $_SESSION["fund_basic_information_form"]["agree_fund_duration"]:"",
	);
	$today = getdate();
	$form["fund_registration_date"] = array(
		"#type" => "date",
		
		"#prefix" => "<tr><th>基金备案时间</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["fund_registration_date"])? $_SESSION["fund_basic_information_form"]["fund_registration_date"]:array("year"=>$today["year"],"month"=>$today["month"],"day"=>$today["mday"]),
	);
			
	$form["fund_offical_number"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>备案文号</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["fund_offical_number"])? $_SESSION["fund_basic_information_form"]["fund_offical_number"]:"",
	);
	$form["fund_investment_committee"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>基金投资委员会名单</th><td colspan=3>",
		"#suffix" => "</td></tr></table>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["fund_investment_committee"])? $_SESSION["fund_basic_information_form"]["fund_investment_committee"]:"",
	);
	/*
	$form["fund_id"] = array(
		"#type" => "hidden",
		"#value" => $fund_id,
	);*/
	$form["submit"] = array(
		"#type" => "submit",
		"#value" => t("提交"),
	);
	return $form;
}

function fund_basic_information_create_form_validate($form, &$form_state){
	if ($form_state['values']['registered_capital'] <= 0) {
	    form_set_error('registered_capital', '注册资本必须大于0，请确认。');
	  }
	if ($form_state['values']['contributed_capital'] < 0) {
	    form_set_error('contributed_capital', '当前实缴资本不能为负数，请确认。');
	  }
}

function fund_basic_information_create_form_submit($form, &$form_state){
	$_SESSION["fund_basic_information_form"] = $form_state["values"];
	//$form_state["redirect"] = "fund_basic_information/confirm/".$form_state["fund_id"];
	$form_state["redirect"] = "fund_basic_information/confirm";
}

//function fund_basic_information_confirm_form($form,&$form_state,$fund_id)
function fund_basic_information_confirm_form($form,&$form_state)
{
	drupal_add_css(drupal_get_path("module","fund_basic_information")."/rkrz_form.css");
	$form["short_name"] = array(
		"#type" => "item",
		
		"#prefix" => "<table><tr><th>基金简称</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["short_name"])? $_SESSION["fund_basic_information_form"]["short_name"]:"",
	);
	$form["registered_name"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>基金注册名称</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["registered_name"])? $_SESSION["fund_basic_information_form"]["registered_name"]:"",
	);
	$form["area"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>所属地区</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["area"])? $_SESSION["fund_basic_information_form"]["area"]:"",
	);
	$form["registered_capital"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>注册资本</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["registered_capital"])? $_SESSION["fund_basic_information_form"]["registered_capital"]:"",
	);
	$form["contributed_capital"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>当前实缴资本</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["contributed_capital"])? $_SESSION["fund_basic_information_form"]["contributed_capital"]:"",
	);
	$form["offical_reference_number"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>批复文号</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["offical_reference_number"])? $_SESSION["fund_basic_information_form"]["offical_reference_number"]:"",
	);
	$today = getdate();
	$form["officaled_date"] = array(
		"#type" => "date",
		
		"#prefix" => "<th>批复时间</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["officaled_date"])? $_SESSION["fund_basic_information_form"]["officaled_date"]:array("year"=>$today["year"],"month"=>$today["month"],"day"=>$today["mday"]),
	);
	$form["organization_form"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>组织形式</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["organization_form"])? $_SESSION["fund_basic_information_form"]["organization_form"]:"",
	);
	$form["organization_number"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>组织机构代码</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["organization_number"])? $_SESSION["fund_basic_information_form"]["organization_number"]:"",
	);
	$today = getdate();
	$form["registration_date"] = array(
		"#type" => "date",
		
		"#prefix" => "<tr><th>注册时间</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["registration_date"])? $_SESSION["fund_basic_information_form"]["registration_date"]:array("year"=>$today["year"],"month"=>$today["month"],"day"=>$today["mday"]),
	);
	$form["registration_address"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>注册地址</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["registration_address"])? $_SESSION["fund_basic_information_form"]["registration_address"]:"",
	);
	$form["office_address"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>办公地址</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["office_address"])? $_SESSION["fund_basic_information_form"]["office_address"]:"",
	);
	$form["postcode"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>邮编</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["postcode"])? $_SESSION["fund_basic_information_form"]["postcode"]:"",
	);
	$form["corporate_representative"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>法人代表</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["corporate_representative"])? $_SESSION["fund_basic_information_form"]["corporate_representative"]:"",
	);
	$form["scope_of_business"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>经营范围</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["scope_of_business"])? $_SESSION["fund_basic_information_form"]["scope_of_business"]:"",
	);
	$form["contact"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>联系人</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["contact"])? $_SESSION["fund_basic_information_form"]["contact"]:"",
	);
	$form["contact_phone"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>联系人电话</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["contact_phone"])? $_SESSION["fund_basic_information_form"]["contact_phone"]:"",
	);
	$form["contact_cellphone"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>联系人手机</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["contact_cellphone"])? $_SESSION["fund_basic_information_form"]["contact_cellphone"]:"",
	);
	$form["contact_fax"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>联系人传真</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["contact_fax"])? $_SESSION["fund_basic_information_form"]["contact_fax"]:"",
	);
	$form["contact_email"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>联系人邮箱</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["contact_email"])? $_SESSION["fund_basic_information_form"]["contact_email"]:"",
	);
	$form["national_financial_management_organization"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>国家财政资金受托管理机构</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["national_financial_management_organization"])? $_SESSION["fund_basic_information_form"]["national_financial_management_organization"]:"",
	);
	$form["nfmo_address"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>地址</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["nfmo_address"])? $_SESSION["fund_basic_information_form"]["nfmo_address"]:"",
	);
	$form["nfmo_registered_capital"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>注册资本</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["nfmo_registered_capital"])? $_SESSION["fund_basic_information_form"]["nfmo_registered_capital"]:"",
	);
	$form["nfmo_contact"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>联系人</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["nfmo_contact"])? $_SESSION["fund_basic_information_form"]["nfmo_contact"]:"",
	);
	$form["nfmo_contact_phone"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>联系人电话</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["nfmo_contact_phone"])? $_SESSION["fund_basic_information_form"]["nfmo_contact_phone"]:"",
	);
	$form["nfmo_contact_cellphone"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>联系人手机</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["nfmo_contact_cellphone"])? $_SESSION["fund_basic_information_form"]["nfmo_contact_cellphone"]:"",
	);
	$form["nfmo_contact_email"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>联系人邮箱</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["nfmo_contact_email"])? $_SESSION["fund_basic_information_form"]["nfmo_contact_email"]:"",
	);
	$form["province_financial_management_organization"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>省级财政资金受托机构</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["province_financial_management_organization"])? $_SESSION["fund_basic_information_form"]["province_financial_management_organization"]:"",
	);
	$form["pfmo_address"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>地址</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["pfmo_address"])? $_SESSION["fund_basic_information_form"]["pfmo_address"]:"",
	);
	$form["pfmo_registered_capital"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>注册资本</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["pfmo_registered_capital"])? $_SESSION["fund_basic_information_form"]["pfmo_registered_capital"]:"",
	);
	$form["pfmo_contact"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>联系人</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["pfmo_contact"])? $_SESSION["fund_basic_information_form"]["pfmo_contact"]:"",
	);
	$form["pfmo_contact_phone"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>联系人电话</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["pfmo_contact_phone"])? $_SESSION["fund_basic_information_form"]["pfmo_contact_phone"]:"",
	);
	$form["pfmo_contact_cellphone"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>联系人手机</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["pfmo_contact_cellphone"])? $_SESSION["fund_basic_information_form"]["pfmo_contact_cellphone"]:"",
	);
	$form["custodian_bank"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>托管银行</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["custodian_bank"])? $_SESSION["fund_basic_information_form"]["custodian_bank"]:"",
	);
	$form["bank_of_deposit"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>开户行</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["bank_of_deposit"])? $_SESSION["fund_basic_information_form"]["bank_of_deposit"]:"",
	);
	$form["bank_contact"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>托管银行联系人</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["bank_contact"])? $_SESSION["fund_basic_information_form"]["bank_contact"]:"",
	);
	$form["bank_contact_cellphone"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>联系人手机</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["bank_contact_cellphone"])? $_SESSION["fund_basic_information_form"]["bank_contact_cellphone"]:"",
	);
	$form["bank_contact_phone"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>联系人电话</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["bank_contact_phone"])? $_SESSION["fund_basic_information_form"]["bank_contact_phone"]:"",
	);
	$form["bank_contact_email"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>联系人邮箱</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["bank_contact_email"])? $_SESSION["fund_basic_information_form"]["bank_contact_email"]:"",
	);
	$form["director_list"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>公司董事名单</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["director_list"])? $_SESSION["fund_basic_information_form"]["director_list"]:"",
	);
	$form["supervisor_list"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>公司监事名单</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["supervisor_list"])? $_SESSION["fund_basic_information_form"]["supervisor_list"]:"",
	);
	$form["investment_field"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>投资产业领域</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["investment_field"])? $_SESSION["fund_basic_information_form"]["investment_field"]:"",
	);
	$form["agree_industry_field"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对产业领域的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#disabled" => true,
		"#default_value" => isset($_SESSION["fund_basic_information_form"]["agree_industry_field"])? $_SESSION["fund_basic_information_form"]["agree_industry_field"]:"",
	);
	$form["agree_investment_phase"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对投资阶段的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#disabled" => true,
		"#default_value" => isset($_SESSION["fund_basic_information_form"]["agree_investment_phase"])? $_SESSION["fund_basic_information_form"]["agree_investment_phase"]:"",
	);
	$form["agree_investment_region"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对投资地域的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#disabled" => true,
		"#default_value" => isset($_SESSION["fund_basic_information_form"]["agree_investment_region"])? $_SESSION["fund_basic_information_form"]["agree_investment_region"]:"",
	);
	$form["agree_management_cost"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对管理费用的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#disabled" => true,
		"#default_value" => isset($_SESSION["fund_basic_information_form"]["agree_management_cost"])? $_SESSION["fund_basic_information_form"]["agree_management_cost"]:"",
	);
	$form["agree_effectiveness_reward"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对效益奖励的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#disabled" => true,
		"#default_value" => isset($_SESSION["fund_basic_information_form"]["agree_effectiveness_reward"])? $_SESSION["fund_basic_information_form"]["agree_effectiveness_reward"]:"",
	);
	$form["agree_contribute_time_percentage"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对出资时间和出资比例的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#disabled" => true,
		"#default_value" => isset($_SESSION["fund_basic_information_form"]["agree_contribute_time_percentage"])? $_SESSION["fund_basic_information_form"]["agree_contribute_time_percentage"]:"",
	);
	$form["agree_fund_duration"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对基金存续期的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#disabled" => true,
		"#default_value" => isset($_SESSION["fund_basic_information_form"]["agree_fund_duration"])? $_SESSION["fund_basic_information_form"]["agree_fund_duration"]:"",
	);
	$today = getdate();
	$form["fund_registration_date"] = array(
		"#type" => "date",
		
		"#prefix" => "<tr><th>基金备案时间</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_basic_information_form"]["fund_registration_date"])? $_SESSION["fund_basic_information_form"]["fund_registration_date"]:array("year"=>$today["year"],"month"=>$today["month"],"day"=>$today["mday"]),
	);
	$form["fund_offical_number"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>备案文号</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["fund_offical_number"])? $_SESSION["fund_basic_information_form"]["fund_offical_number"]:"",
	);
	$form["fund_investment_committee"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>基金投资委员会名单</th><td colspan=3>",
		"#suffix" => "</td></tr></table>",

		"#markup" => isset($_SESSION["fund_basic_information_form"]["fund_investment_committee"])? $_SESSION["fund_basic_information_form"]["fund_investment_committee"]:"",
	);
	$form["back"] = array(
		"#type" => "submit",
		"#value" => t("返回"),
		"#submit" => array("fund_basic_information_confirm_form_back"),
	);
	/*
	$form["fund_id"] = array(
		"#type" => "hidden",
		"#value" => $fund_id,
	);*/
	$form["submit"] = array(
		"#type" => "submit",
		"#value" => t("提交"),
	);
	return $form;
}

function fund_basic_information_confirm_form_back($form, &$form_state)
{
	//$form_state["redirect"] = "fund_basic_information/create/".$form_state["fund_id"];
	$form_state["redirect"] = "fund_basic_information/create";
}

function fund_basic_information_confirm_form_submit($form, &$form_state)
{
	$values = NULL;
	if(empty($_SESSION["fund_basic_information_form"])){
		$form_state['redirect'] = "fund_basic_information";
	}else{
		$values = $_SESSION["fund_basic_information_form"];
		unset($_SESSION["fund_basic_information_form"]);
	}
	
	//$query = "INSERT INTO {fund_basic_information} (id, user_id, fund_id, short_name, registered_name, area, registered_capital, contributed_capital, offical_reference_number, officaled_date, organization_form, organization_number, registration_date, registration_address, office_address, postcode, corporate_representative, scope_of_business, contact, contact_phone, contact_cellphone, contact_fax, contact_email, national_financial_management_organization, nfmo_address, nfmo_registered_capital, nfmo_contact, nfmo_contact_phone, nfmo_contact_cellphone, nfmo_contact_email, province_financial_management_organization, pfmo_address, pfmo_registered_capital, pfmo_contact, pfmo_contact_phone, pfmo_contact_cellphone, custodian_bank, bank_of_deposit, bank_contact, bank_contact_cellphone, bank_contact_phone, bank_contact_email, director_list, supervisor_list, investment_field, agree_industry_field, agree_investment_phase, agree_investment_region, agree_management_cost, agree_effectiveness_reward, agree_contribute_time_percentage, agree_fund_duration, fund_registration_date, fund_offical_number, fund_investment_committee) VALUES (null, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
	$query = "INSERT INTO {fund_basic_information} (id, user_id, short_name, registered_name, area, registered_capital, contributed_capital, offical_reference_number, officaled_date, organization_form, organization_number, registration_date, registration_address, office_address, postcode, corporate_representative, scope_of_business, contact, contact_phone, contact_cellphone, contact_fax, contact_email, national_financial_management_organization, nfmo_address, nfmo_registered_capital, nfmo_contact, nfmo_contact_phone, nfmo_contact_cellphone, nfmo_contact_email, province_financial_management_organization, pfmo_address, pfmo_registered_capital, pfmo_contact, pfmo_contact_phone, pfmo_contact_cellphone, custodian_bank, bank_of_deposit, bank_contact, bank_contact_cellphone, bank_contact_phone, bank_contact_email, director_list, supervisor_list, investment_field, agree_industry_field, agree_investment_phase, agree_investment_region, agree_management_cost, agree_effectiveness_reward, agree_contribute_time_percentage, agree_fund_duration, fund_registration_date, fund_offical_number, fund_investment_committee) VALUES (null, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
	$officaled_date_times = mktime(0,0,0,$values["officaled_date"]["month"],$values["officaled_date"]["day"],$values["officaled_date"]["year"]);
	$registration_date_times = mktime(0,0,0,$values["registration_date"]["month"],$values["registration_date"]["day"],$values["registration_date"]["year"]);
	$fund_registration_date_times = mktime(0,0,0,$values["fund_registration_date"]["month"],$values["fund_registration_date"]["day"],$values["fund_registration_date"]["year"]);
	global $user;
	$args = array(
		$user->uid,
		//$values["fund_id"],
		$values["short_name"],
		$values["registered_name"],
		$values["area"],
		$values["registered_capital"],
		$values["contributed_capital"],
		$values["offical_reference_number"],
		$officaled_date_times,
		$values["organization_form"],
		$values["organization_number"],
		$registration_date_times,
		$values["registration_address"],
		$values["office_address"],
		$values["postcode"],
		$values["corporate_representative"],
		$values["scope_of_business"],
		$values["contact"],
		$values["contact_phone"],
		$values["contact_cellphone"],
		$values["contact_fax"],
		$values["contact_email"],
		$values["national_financial_management_organization"],
		$values["nfmo_address"],
		$values["nfmo_registered_capital"],
		$values["nfmo_contact"],
		$values["nfmo_contact_phone"],
		$values["nfmo_contact_cellphone"],
		$values["nfmo_contact_email"],
		$values["province_financial_management_organization"],
		$values["pfmo_address"],
		$values["pfmo_registered_capital"],
		$values["pfmo_contact"],
		$values["pfmo_contact_phone"],
		$values["pfmo_contact_cellphone"],
		$values["custodian_bank"],
		$values["bank_of_deposit"],
		$values["bank_contact"],
		$values["bank_contact_cellphone"],
		$values["bank_contact_phone"],
		$values["bank_contact_email"],
		$values["director_list"],
		$values["supervisor_list"],
		$values["investment_field"],
		$values["agree_industry_field"],
		$values["agree_investment_phase"],
		$values["agree_investment_region"],
		$values["agree_management_cost"],
		$values["agree_effectiveness_reward"],
		$values["agree_contribute_time_percentage"],
		$values["agree_fund_duration"],
		$fund_registration_date_times,
		$values["fund_offical_number"],
		$values["fund_investment_committee"],
	);
	db_query($query,$args);
	$form_state["redirect"] = "fund_basic_information";
}

function fund_basic_information_view_form($form, &$form_state, $perid)
{
	drupal_add_css(drupal_get_path("module","fund_basic_information")."/rkrz_form.css");
	$query = "SELECT * FROM {fund_basic_information} WHERE id = ?";
	$query_result = db_query($query, array($perid));
	$result_values = "";
	foreach ($query_result as $result_values)
	{
	}
	$form["#prefix"] = '<div id="printable">';
	$form["#suffix"] = '</div>';
	$form["short_name"] = array(
		"#type" => "item",
		
		"#prefix" => "<table><tr><th>基金简称</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->short_name,
	);
	$form["registered_name"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>基金注册名称</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->registered_name,
	);
	$form["area"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>所属地区</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->area,
	);
	$form["registered_capital"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>注册资本</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->registered_capital,
	);
	$form["contributed_capital"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>当前实缴资本</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->contributed_capital,
	);
	$form["offical_reference_number"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>批复文号</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->offical_reference_number,
	);
	$theday = getdate($result_values->officaled_date);
	$form["officaled_date"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>批复时间</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => format_date($result_values->officaled_date,"custom","Y-m-d"),
	);
			
	$form["organization_form"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>组织形式</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->organization_form,
	);
	$form["organization_number"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>组织机构代码</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->organization_number,
	);
	$theday = getdate($result_values->registration_date);
	$form["registration_date"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>注册时间</th><td>",
		"#suffix" => "</td>",

		"#markup" => format_date($result_values->registration_date,"custom","Y-m-d"),
	);
			
	$form["registration_address"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>注册地址</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->registration_address,
	);
	$form["office_address"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>办公地址</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->office_address,
	);
	$form["postcode"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>邮编</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->postcode,
	);
	$form["corporate_representative"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>法人代表</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->corporate_representative,
	);
	$form["scope_of_business"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>经营范围</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->scope_of_business,
	);
	$form["contact"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>联系人</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->contact,
	);
	$form["contact_phone"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>联系人电话</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->contact_phone,
	);
	$form["contact_cellphone"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>联系人手机</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->contact_cellphone,
	);
	$form["contact_fax"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>联系人传真</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->contact_fax,
	);
	$form["contact_email"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>联系人邮箱</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->contact_email,
	);
	$form["national_financial_management_organization"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>国家财政资金受托管理机构</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->national_financial_management_organization,
	);
	$form["nfmo_address"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>地址</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->nfmo_address,
	);
	$form["nfmo_registered_capital"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>注册资本</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->nfmo_registered_capital,
	);
	$form["nfmo_contact"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>联系人</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->nfmo_contact,
	);
	$form["nfmo_contact_phone"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>联系人电话</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->nfmo_contact_phone,
	);
	$form["nfmo_contact_cellphone"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>联系人手机</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->nfmo_contact_cellphone,
	);
	$form["nfmo_contact_email"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>联系人邮箱</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->nfmo_contact_email,
	);
	$form["province_financial_management_organization"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>省级财政资金受托机构</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->province_financial_management_organization,
	);
	$form["pfmo_address"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>地址</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->pfmo_address,
	);
	$form["pfmo_registered_capital"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>注册资本</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->pfmo_registered_capital,
	);
	$form["pfmo_contact"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>联系人</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->pfmo_contact,
	);
	$form["pfmo_contact_phone"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>联系人电话</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->pfmo_contact_phone,
	);
	$form["pfmo_contact_cellphone"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>联系人手机</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->pfmo_contact_cellphone,
	);
	$form["custodian_bank"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>托管银行</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->custodian_bank,
	);
	$form["bank_of_deposit"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>开户行</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->bank_of_deposit,
	);
	$form["bank_contact"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>托管银行联系人</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->bank_contact,
	);
	$form["bank_contact_cellphone"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>联系人手机</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->bank_contact_cellphone,
	);
	$form["bank_contact_phone"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>联系人电话</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->bank_contact_phone,
	);
	$form["bank_contact_email"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>联系人邮箱</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->bank_contact_email,
	);
	$form["director_list"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>公司董事名单</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->director_list,
	);
	$form["supervisor_list"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>公司监事名单</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->supervisor_list,
	);
	$form["investment_field"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>投资产业领域</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->investment_field,
	);
	$form["agree_industry_field"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对产业领域的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#disabled" => true,
		"#default_value" => $result_values->agree_industry_field,
	);
	$form["agree_investment_phase"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对投资阶段的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#disabled" => true,
		"#default_value" => $result_values->agree_investment_phase,
	);
	$form["agree_investment_region"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对投资地域的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#disabled" => true,
		"#default_value" => $result_values->agree_investment_region,
	);
	$form["agree_management_cost"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对管理费用的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#disabled" => true,
		"#default_value" => $result_values->agree_management_cost,
	);
	$form["agree_effectiveness_reward"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对效益奖励的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#disabled" => true,
		"#default_value" => $result_values->agree_effectiveness_reward,
	);
	$form["agree_contribute_time_percentage"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对出资时间和出资比例的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#disabled" => true,
		"#default_value" => $result_values->agree_contribute_time_percentage,
	);
	$form["agree_fund_duration"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对基金存续期的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#disabled" => true,
		"#default_value" => $result_values->agree_fund_duration,
	);
	$theday = getdate($result_values->fund_registration_date);
	$form["fund_registration_date"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>基金备案时间</th><td>",
		"#suffix" => "</td>",

		"#markup" => format_date($result_values->fund_registration_date,"custom","Y-m-d"),
	);
			
	$form["fund_offical_number"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>备案文号</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->fund_offical_number,
	);
	$form["fund_investment_committee"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>基金投资委员会名单</th><td colspan=3>",
		"#suffix" => "</td></tr></table>",

		"#markup" => $result_values->fund_investment_committee,
	);
		return $form;
}

function fund_basic_information_view_form_submit($form, &$form_state){
	$form_state["redirect"] = "fund_basic_information";
}

function fund_basic_information_edit_form($form, &$form_state, $perid)
{
	drupal_add_css(drupal_get_path("module","fund_basic_information")."/rkrz_form.css");
	$query = "SELECT * FROM {fund_basic_information} WHERE id = ?";
	$query_result = db_query($query, array($perid));
	$result_values = "";
	foreach ($query_result as $result_values)
	{
	}
	$form["short_name"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<table><tr><th>基金简称</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->short_name,
	);
	$form["registered_name"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>基金注册名称</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->registered_name,
	);
	$form["area"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>所属地区</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->area,
	);
	$form["registered_capital"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>注册资本</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->registered_capital,
	);
	$form["contributed_capital"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>当前实缴资本</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->contributed_capital,
	);
	$form["offical_reference_number"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>批复文号</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->offical_reference_number,
	);
	$today = getdate($result_values->officaled_date);
	$form["officaled_date"] = array(
		"#type" => "date",
		
		"#prefix" => "<th>批复时间</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => array("year"=>$today["year"],"month"=>$today["month"],"day"=>$today["mday"]),
	);
			
	$form["organization_form"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>组织形式</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->organization_form,
	);
	$form["organization_number"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>组织机构代码</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->organization_number,
	);
	$today = getdate($result_values->registration_date);
	$form["registration_date"] = array(
		"#type" => "date",
		
		"#prefix" => "<tr><th>注册时间</th><td>",
		"#suffix" => "</td>",

		"#default_value" => array("year"=>$today["year"],"month"=>$today["month"],"day"=>$today["mday"]),
	);
			
	$form["registration_address"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>注册地址</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->registration_address,
	);
	$form["office_address"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>办公地址</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->office_address,
	);
	$form["postcode"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>邮编</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->postcode,
	);
	$form["corporate_representative"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>法人代表</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->corporate_representative,
	);
	$form["scope_of_business"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>经营范围</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->scope_of_business,
	);
	$form["contact"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>联系人</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->contact,
	);
	$form["contact_phone"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>联系人电话</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->contact_phone,
	);
	$form["contact_cellphone"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>联系人手机</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->contact_cellphone,
	);
	$form["contact_fax"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>联系人传真</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->contact_fax,
	);
	$form["contact_email"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>联系人邮箱</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->contact_email,
	);
	$form["national_financial_management_organization"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>国家财政资金受托管理机构</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->national_financial_management_organization,
	);
	$form["nfmo_address"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>地址</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->nfmo_address,
	);
	$form["nfmo_registered_capital"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>注册资本</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->nfmo_registered_capital,
	);
	$form["nfmo_contact"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>联系人</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->nfmo_contact,
	);
	$form["nfmo_contact_phone"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>联系人电话</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->nfmo_contact_phone,
	);
	$form["nfmo_contact_cellphone"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>联系人手机</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->nfmo_contact_cellphone,
	);
	$form["nfmo_contact_email"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>联系人邮箱</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->nfmo_contact_email,
	);
	$form["province_financial_management_organization"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>省级财政资金受托机构</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->province_financial_management_organization,
	);
	$form["pfmo_address"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>地址</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->pfmo_address,
	);
	$form["pfmo_registered_capital"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>注册资本</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->pfmo_registered_capital,
	);
	$form["pfmo_contact"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>联系人</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->pfmo_contact,
	);
	$form["pfmo_contact_phone"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>联系人电话</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->pfmo_contact_phone,
	);
	$form["pfmo_contact_cellphone"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>联系人手机</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->pfmo_contact_cellphone,
	);
	$form["custodian_bank"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>托管银行</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->custodian_bank,
	);
	$form["bank_of_deposit"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>开户行</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->bank_of_deposit,
	);
	$form["bank_contact"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>托管银行联系人</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->bank_contact,
	);
	$form["bank_contact_cellphone"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>联系人手机</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->bank_contact_cellphone,
	);
	$form["bank_contact_phone"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>联系人电话</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->bank_contact_phone,
	);
	$form["bank_contact_email"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>联系人邮箱</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->bank_contact_email,
	);
	$form["director_list"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>公司董事名单</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->director_list,
	);
	$form["supervisor_list"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>公司监事名单</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->supervisor_list,
	);
	$form["investment_field"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>投资产业领域</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->investment_field,
	);
	$form["agree_industry_field"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对产业领域的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->agree_industry_field,
	);
	$form["agree_investment_phase"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对投资阶段的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->agree_investment_phase,
	);
	$form["agree_investment_region"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对投资地域的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->agree_investment_region,
	);
	$form["agree_management_cost"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对管理费用的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->agree_management_cost,
	);
	$form["agree_effectiveness_reward"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对效益奖励的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->agree_effectiveness_reward,
	);
	$form["agree_contribute_time_percentage"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对出资时间和出资比例的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->agree_contribute_time_percentage,
	);
	$form["agree_fund_duration"] = array(
		"#type" => "textarea",
		
		"#prefix" => "<tr><th>基金章程/合伙人协议对基金存续期的约定</th><td colspan=3>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->agree_fund_duration,
	);
	$today = getdate($result_values->fund_registration_date);
	$form["fund_registration_date"] = array(
		"#type" => "date",
		
		"#prefix" => "<tr><th>基金备案时间</th><td>",
		"#suffix" => "</td>",

		"#default_value" => array("year"=>$today["year"],"month"=>$today["month"],"day"=>$today["mday"]),
	);
			
	$form["fund_offical_number"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>备案文号</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->fund_offical_number,
	);
	$form["fund_investment_committee"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>基金投资委员会名单</th><td colspan=3>",
		"#suffix" => "</td></tr></table>",

		"#default_value" => $result_values->fund_investment_committee,
	);
	$form["perid"] = array(
	"#type" => "hidden",
	"#value" => $perid, 
	);
	$form["submit"] = array(
		"#type" => "submit",
		"#value" => t("提交"),
	);
	return $form;
}

function fund_basic_information_edit_form_validate($form, &$form_state){
	if ($form_state['values']['registered_capital'] <= 0) {
	    form_set_error('registered_capital', '注册资本必须大于0，请确认。');
	  }
	if ($form_state['values']['contributed_capital'] < 0) {
	    form_set_error('contributed_capital', '当前实缴资本不能为负数，请确认。');
	  }
}

function fund_basic_information_edit_form_submit($form, &$form_state){
	$values = $form_state["values"];
	$officaled_date_times = mktime(0,0,0,$values["officaled_date"]["month"],$values["officaled_date"]["day"],$values["officaled_date"]["year"]);
	$registration_date_times = mktime(0,0,0,$values["registration_date"]["month"],$values["registration_date"]["day"],$values["registration_date"]["year"]);
	$fund_registration_date_times = mktime(0,0,0,$values["fund_registration_date"]["month"],$values["fund_registration_date"]["day"],$values["fund_registration_date"]["year"]);
	
	db_update('fund_basic_information')
  		->fields(array(
   			    "short_name"=>$values["short_name"],
				"registered_name"=>$values["registered_name"],
				"area"=>$values["area"],
				"registered_capital"=>$values["registered_capital"],
				"contributed_capital"=>$values["contributed_capital"],
				"offical_reference_number"=>$values["offical_reference_number"],
				"officaled_date"=>$officaled_date_times,
				"organization_form"=>$values["organization_form"],
				"organization_number"=>$values["organization_number"],
				"registration_date"=>$registration_date_times,
				"registration_address"=>$values["registration_address"],
				"office_address"=>$values["office_address"],
				"postcode"=>$values["postcode"],
				"corporate_representative"=>$values["corporate_representative"],
				"scope_of_business"=>$values["scope_of_business"],
				"contact"=>$values["contact"],
				"contact_phone"=>$values["contact_phone"],
				"contact_cellphone"=>$values["contact_cellphone"],
				"contact_fax"=>$values["contact_fax"],
				"contact_email"=>$values["contact_email"],
				"national_financial_management_organization"=>$values["national_financial_management_organization"],
				"nfmo_address"=>$values["nfmo_address"],
				"nfmo_registered_capital"=>$values["nfmo_registered_capital"],
				"nfmo_contact"=>$values["nfmo_contact"],
				"nfmo_contact_phone"=>$values["nfmo_contact_phone"],
				"nfmo_contact_cellphone"=>$values["nfmo_contact_cellphone"],
				"nfmo_contact_email"=>$values["nfmo_contact_email"],
				"province_financial_management_organization"=>$values["province_financial_management_organization"],
				"pfmo_address"=>$values["pfmo_address"],
				"pfmo_registered_capital"=>$values["pfmo_registered_capital"],
				"pfmo_contact"=>$values["pfmo_contact"],
				"pfmo_contact_phone"=>$values["pfmo_contact_phone"],
				"pfmo_contact_cellphone"=>$values["pfmo_contact_cellphone"],
				"custodian_bank"=>$values["custodian_bank"],
				"bank_of_deposit"=>$values["bank_of_deposit"],
				"bank_contact"=>$values["bank_contact"],
				"bank_contact_cellphone"=>$values["bank_contact_cellphone"],
				"bank_contact_phone"=>$values["bank_contact_phone"],
				"bank_contact_email"=>$values["bank_contact_email"],
				"director_list"=>$values["director_list"],
				"supervisor_list"=>$values["supervisor_list"],
				"investment_field"=>$values["investment_field"],
				"agree_industry_field"=>$values["agree_industry_field"],
				"agree_investment_phase"=>$values["agree_investment_phase"],
				"agree_investment_region"=>$values["agree_investment_region"],
				"agree_management_cost"=>$values["agree_management_cost"],
				"agree_effectiveness_reward"=>$values["agree_effectiveness_reward"],
				"agree_contribute_time_percentage"=>$values["agree_contribute_time_percentage"],
				"agree_fund_duration"=>$values["agree_fund_duration"],
				"fund_registration_date"=>$fund_registration_date_times,
				"fund_offical_number"=>$values["fund_offical_number"],
				"fund_investment_committee"=>$values["fund_investment_committee"],
  			))
  		->condition('id', $values["perid"])
  		->execute();
}

function fund_manager_intro_fund_choose_page($fund_basic_id) {
  drupal_set_title('对应基金选择');
  $page_content = '';
  $page_content .= l('返回基金列表','fund_basic_information/list') . '<br />'. '<br />';
   $query = "SELECT id, short_name FROM " .
           "{fund_basic_information} where id = ?";
  $queryResult = db_query($query, array($fund_basic_id));
  foreach($queryResult as $result){
  	$page_content .= '当前基金：' . '&nbsp;&nbsp;'. $result->short_name.'<br><br>';
  }
  //该页面的正文为一个表单，注意对于表单，这里需要使用drupal_render呈现一下。
  $render_array = array(
  		'#markup' => $page_content,
  );
  $form = drupal_get_form('fund_manager_intro_fund_choose_form', $fund_basic_id);
  $render_array['#markup'] .= drupal_render($form ); 
  
  return $render_array; 
}

function fund_manager_intro_fund_choose_form($form, &$form_state, $perid){
  $query = "SELECT fund_id FROM " .
           "{fund_basic_information} where id = ?";
  $fund_list = db_query($query, array($perid));	
  $fund = '';
  foreach ($fund_list as $fund) {
      $fund = $fund->fund_id;
  }
  $query = "SELECT id ,name,principal_name,remark FROM " .
           "{guiding_fund_info} ";
  $queryResult = db_query($query);	
  
  $header = array(
    'name' => t('基金名称'),
    'principal_name' => t('管理人'),
    'remark' => t('备注'),
    'choose' => t('已选择(空表示未选择)'),
  );
  $options = array();
  foreach ($queryResult as $node) {
  	$state = '';
  	if($node->id == $fund){
  		$state=  '已选择';
  	}
    $options[$node->id] =array(
      'name' =>  l($node->name, 'guidingfund/list/'. $node->id),
      'principal_name' => $node->principal_name,
      'remark' => $node->remark,
      'choose' => $state,   
    );
  }
  $form['bid'] = array('#type' => 'hidden', '#value' => $perid);
  $form['table'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => t('没有基金记录'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('提交'),
  );
  return $form;  
}

function fund_manager_intro_fund_choose_form_submit($form, &$form_state){
	 $values = $form_state['values'];		
	 $fund = '';
	 
	 foreach ($values['table'] as $rows) {
	 	if($rows!=0)
		 	$fund = $rows;
     }
	  db_update('fund_basic_information')
  		->fields(array(
   			 'fund_id' => $fund,
  			))
  		->condition('id', $values['bid'])
  		->execute();
	// $form_state['redirect'] = 'fund_basic_information/fund_choose/'.$values['bid'];	
	 
}

function fund_manager_intro_page()
{
	$html = array("#markup" => "");
	return $html;
}

function fund_manager_intro_create_page($fund_id)
{
	$html = array("#markup" => "");
	$create_form = drupal_get_form("fund_manager_intro_create_form",$fund_id);
	$html["#markup"] .= drupal_render($create_form);
	return $html;
}

function fund_manager_intro_confirm_page($fund_id)
{
	$html = array("#markup" => "");
	$confirm_form = drupal_get_form("fund_manager_intro_confirm_form",$fund_id);
	$html["#markup"] .= drupal_render($confirm_form);
	return $html;
}

function fund_manager_intro_view_page($fund_id)
{
	$html = array("#markup" => "");
	$query = "SELECT id FROM " .
           "{fund_manager_intro} where fund_id = ?";
    $queryResult = db_query($query, array($fund_id));
    $ifempty =TRUE;
    foreach ($queryResult as $links ) {
	   if($links->id>0)
		  $ifempty = FALSE;
    }
    if($ifempty)
	 {
	 	 $view_form = drupal_get_form("fund_manager_intro_create_form",$fund_id);
		 $html["#markup"] .= drupal_render($view_form);
	 }
	else{
		$view_form = drupal_get_form("fund_manager_intro_view_form",$fund_id);
		$html["#markup"] .= l("返回列表","fund_basic_information").'&nbsp;&nbsp;';

		$html["#markup"] .= l("编辑","fund_manager_intro/edit/".$fund_id).'&nbsp;&nbsp;';
		$options = array(
		'target_id' => 'printable',
		'value' => t('打印'),
		'type' => 'link');
		$html["#markup"] .= area_print_form($options);
		$html["#markup"] .= drupal_render($view_form);
		$header = array(
		array("data" => "主要股东/合伙人", "field" => "principal_shareholder"),
		array("data" => "出资额（万元）", "field" => "contribution_amount"),
		array("data" => "操作"),
		);
		$query = db_select("shareholder_info","n")
		->extend("PagerDefault")
		->limit(10)
		->extend("TableSort")
		->orderByHeader($header)
		->fields("n", array(
		"id",
		"principal_shareholder",
		"contribution_amount",
		))
		->condition('fund_id',$fund_id,'=');
		$results = $query->execute();
		$rows = array();
		foreach ($results as $node) {
			$rows[] = array(
			"data" => array(
			$node->principal_shareholder,
			$node->contribution_amount,
			l("详情","shareholder_info/edit/".$node->id),
			));
		}
		$html["#markup"] .= theme("table",
		array(
			"header" => $header,
			"rows" => $rows,
			"sticky" => TRUE,
			"empty" => "没有记录",
		));
		$html["#markup"] .= theme("pager",
		array(
			"tags" => array()
		));
		$html["#markup"] .= l("增加股东","shareholder_info/create/".$fund_id);
	}
	
	return $html;
}

function fund_manager_intro_edit_page($fund_id)
{
    $ifempty =TRUE;
	$query = "SELECT id FROM " .
           "{fund_manager_intro} where fund_id = ?";
    $queryResult = db_query($query, array($fund_id));
    $ifempty =TRUE;
    foreach ($queryResult as $links ) {
	   if($links->id>0)
		  $ifempty = FALSE;
    }
	if($ifempty)
	 {
	 	 $view_form = drupal_get_form("fund_manager_intro_create_form",$fund_id);
		 $html["#markup"] .= drupal_render($view_form);
	 }
	else{
		$html = array("#markup" => "");
		$html["#markup"] .= l("返回列表","fund_basic_information").'&nbsp;&nbsp;';
		$html["#markup"] .= l("浏览","fund_manager_intro/view/".$fund_id);
		$edit_form = drupal_get_form("fund_manager_intro_edit_form",$fund_id);
		$html["#markup"] .= drupal_render($edit_form);	
	}
	return $html;
}

function fund_manager_intro_list_page()
{
	$html = array("#markup" => "");
	$header = array(
	array("data" => "详情"),
	);
	$query = db_select("fund_manager_intro","n")
	->extend("PagerDefault")
	->limit(10)
	->extend("TableSort")
	->orderByHeader($header)
	->fields("n", array(
	"id",
	));
	$results = $query->execute();
	$rows = array();
	foreach ($results as $node) {
		$rows[] = array(
		"data" => array(
		l("详情","fund_manager_intro/view/".$node->id),
		));
	}
	$html["#markup"] .= theme("table",
	array(
		"header" => $header,
		"rows" => $rows,
		"sticky" => TRUE,
		"empty" => "没有记录",
	));
	$html["#markup"] .= theme("pager",
	array(
		"tags" => array()
	));
	return $html;
}

function fund_manager_intro_create_form($form,&$form_state,$fund_id)
{
	drupal_add_css(drupal_get_path("module","fund_basic_information")."/rkrz_form.css");
	$form["fund_manager"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<table><tr><th>基金管理人</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_manager_intro_form"]["fund_manager"])? $_SESSION["fund_manager_intro_form"]["fund_manager"]:"",
	);
	$form["organization_form"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>组织形式</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_manager_intro_form"]["organization_form"])? $_SESSION["fund_manager_intro_form"]["organization_form"]:"",
	);
	$form["register_capital"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>注册资本</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_manager_intro_form"]["register_capital"])? $_SESSION["fund_manager_intro_form"]["register_capital"]:1,
	);
	$today = getdate();
	$form["established_time"] = array(
		"#type" => "date",
		
		"#prefix" => "<th>成立时间</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_manager_intro_form"]["established_time"])? $_SESSION["fund_manager_intro_form"]["established_time"]:array("year"=>$today["year"],"month"=>$today["month"],"day"=>$today["mday"]),
	);
			
	$form["corporate_representative"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>法人代表</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_manager_intro_form"]["corporate_representative"])? $_SESSION["fund_manager_intro_form"]["corporate_representative"]:"",
	);
	$form["president"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>总经理</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_manager_intro_form"]["president"])? $_SESSION["fund_manager_intro_form"]["president"]:"",
	);
	$form["contact"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>联系人</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_manager_intro_form"]["contact"])? $_SESSION["fund_manager_intro_form"]["contact"]:"",
	);
	$form["contact_phone"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>联系电话</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_manager_intro_form"]["contact_phone"])? $_SESSION["fund_manager_intro_form"]["contact_phone"]:"",
	);
	$form["contact_cellphone"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>手机</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_manager_intro_form"]["contact_cellphone"])? $_SESSION["fund_manager_intro_form"]["contact_cellphone"]:"",
	);
	$form["contact_fax"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>传真</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_manager_intro_form"]["contact_fax"])? $_SESSION["fund_manager_intro_form"]["contact_fax"]:"",
	);
	$form["contact_mail"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>邮箱</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_manager_intro_form"]["contact_mail"])? $_SESSION["fund_manager_intro_form"]["contact_mail"]:"",
	);
	$form["contact_postcode"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>邮编</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_manager_intro_form"]["contact_postcode"])? $_SESSION["fund_manager_intro_form"]["contact_postcode"]:"",
	);
	$form["registration_address"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>注册地址</th><td>",
		"#suffix" => "</td>",

		"#default_value" => isset($_SESSION["fund_manager_intro_form"]["registration_address"])? $_SESSION["fund_manager_intro_form"]["registration_address"]:"",
	);
	$form["office_address"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>办公地址</th><td>",
		"#suffix" => "</td></tr></table>",

		"#default_value" => isset($_SESSION["fund_manager_intro_form"]["office_address"])? $_SESSION["fund_manager_intro_form"]["office_address"]:"",
	);
	$form["fund_id"] = array(
		"#type" => "hidden",
		"#value" => $fund_id,
	);
	$form["submit"] = array(
		"#type" => "submit",
		"#value" => t("提交"),
	);
	return $form;
}

function fund_manager_intro_create_form_submit($form, &$form_state){
	$_SESSION["fund_manager_intro_form"] = $form_state["values"];
	$form_state["redirect"] = "fund_manager_intro/confirm/".$form_state["values"]["fund_id"];
}

function fund_manager_intro_create_form_validate($form, &$form_state){
	if ($form_state['values']['register_capital'] <= 0) {
	    form_set_error('register_capital', '注册资本必须大于0，请确认。');
	  }
}

function fund_manager_intro_confirm_form($form,&$form_state,$fund_id)
{
	drupal_add_css(drupal_get_path("module","fund_basic_information")."/rkrz_form.css");
	$form["fund_manager"] = array(
		"#type" => "item",
		
		"#prefix" => "<table><tr><th>基金管理人</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_manager_intro_form"]["fund_manager"])? $_SESSION["fund_manager_intro_form"]["fund_manager"]:"",
	);
	$form["organization_form"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>组织形式</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_manager_intro_form"]["organization_form"])? $_SESSION["fund_manager_intro_form"]["organization_form"]:"",
	);
	$form["register_capital"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>注册资本</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_manager_intro_form"]["register_capital"])? $_SESSION["fund_manager_intro_form"]["register_capital"]:"",
	);
	$today = getdate();
	$form["established_time"] = array(
		"#type" => "date",
		
		"#prefix" => "<th>成立时间</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => isset($_SESSION["fund_manager_intro_form"]["established_time"])? $_SESSION["fund_manager_intro_form"]["established_time"]:array("year"=>$today["year"],"month"=>$today["month"],"day"=>$today["mday"]),
	);
	$form["corporate_representative"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>法人代表</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_manager_intro_form"]["corporate_representative"])? $_SESSION["fund_manager_intro_form"]["corporate_representative"]:"",
	);
	$form["president"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>总经理</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_manager_intro_form"]["president"])? $_SESSION["fund_manager_intro_form"]["president"]:"",
	);
	$form["contact"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>联系人</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_manager_intro_form"]["contact"])? $_SESSION["fund_manager_intro_form"]["contact"]:"",
	);
	$form["contact_phone"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>联系电话</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_manager_intro_form"]["contact_phone"])? $_SESSION["fund_manager_intro_form"]["contact_phone"]:"",
	);
	$form["contact_cellphone"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>手机</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_manager_intro_form"]["contact_cellphone"])? $_SESSION["fund_manager_intro_form"]["contact_cellphone"]:"",
	);
	$form["contact_fax"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>传真</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_manager_intro_form"]["contact_fax"])? $_SESSION["fund_manager_intro_form"]["contact_fax"]:"",
	);
	$form["contact_mail"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>邮箱</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_manager_intro_form"]["contact_mail"])? $_SESSION["fund_manager_intro_form"]["contact_mail"]:"",
	);
	$form["contact_postcode"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>邮编</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => isset($_SESSION["fund_manager_intro_form"]["contact_postcode"])? $_SESSION["fund_manager_intro_form"]["contact_postcode"]:"",
	);
	$form["registration_address"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>注册地址</th><td>",
		"#suffix" => "</td>",

		"#markup" => isset($_SESSION["fund_manager_intro_form"]["registration_address"])? $_SESSION["fund_manager_intro_form"]["registration_address"]:"",
	);
	$form["office_address"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>办公地址</th><td>",
		"#suffix" => "</td></tr></table>",

		"#markup" => isset($_SESSION["fund_manager_intro_form"]["office_address"])? $_SESSION["fund_manager_intro_form"]["office_address"]:"",
	);
	$form["back"] = array(
		"#type" => "submit",
		"#value" => t("返回"),
		"#submit" => array("fund_manager_intro_confirm_form_back"),
	);
	$form["fund_id"] = array(
		"#type" => "hidden",
		"#value" => $fund_id,
	);
	$form["submit"] = array(
		"#type" => "submit",
		"#value" => t("提交"),
	);
	return $form;
}

function fund_manager_intro_confirm_form_back($form, &$form_state)
{
	$fund_id = $form_state["vlaues"]["fund_id"];
	$form_state["redirect"] = "fund_manager_intro/create/".$fund_id;
}

function fund_manager_intro_confirm_form_submit($form, &$form_state)
{
	$values = NULL;
	if(empty($_SESSION["fund_manager_intro_form"])){
		$form_state['redirect'] = "fund_manager_intro";
	}else{
		$values = $_SESSION["fund_manager_intro_form"];
		unset($_SESSION["fund_manager_intro_form"]);
	}
	$established_time_times = mktime(0,0,0,$values["established_time"]["month"],$values["established_time"]["day"],$values["established_time"]["year"]);
	global $user;
	$last_id = db_insert('fund_manager_intro')
  		->fields(array(
   			'user_id'=> $user->uid,
			'fund_id'=> $values["fund_id"],
			'fund_manager'=> $values["fund_manager"],
			'organization_form'=> $values["organization_form"],
			'register_capital'=> $values["register_capital"],
			'established_time'=> $established_time_times,
			'corporate_representative'=> $values["corporate_representative"],
			'president'=> $values["president"],
			'contact'=> $values["contact"],
			'contact_phone'=> $values["contact_phone"],
			'contact_cellphone'=> $values["contact_cellphone"],
			'contact_fax'=> $values["contact_fax"],
			'contact_mail'=> $values["contact_mail"],
			'contact_postcode'=> $values["contact_postcode"],
			'registration_address'=> $values["registration_address"],
			'office_address'=> $values["office_address"],
  			))->execute();
			
	$form_state["redirect"] = "fund_manager_intro/view/".$last_id;
}

function fund_manager_intro_view_form($form, &$form_state, $fund_id)
{
	$query = "SELECT * FROM {fund_manager_intro} WHERE fund_id = ?";
	$query_result = db_query($query, array($fund_id));
	$result_values = "";
	foreach ($query_result as $result_values)
	{
	}
	drupal_add_css(drupal_get_path("module","fund_basic_information")."/rkrz_form.css");
	$form["#prefix"] = '<div id="printable">';
	$form["#suffix"] = '</div>';
	$form["fund_manager"] = array(
		"#type" => "item",
		
		"#prefix" => "<table><tr><th>基金管理人</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->fund_manager,
	);
	$form["organization_form"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>组织形式</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->organization_form,
	);
	$form["register_capital"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>注册资本</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->register_capital,
	);
	$theday = getdate($result_values->established_time);
	$form["established_time"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>成立时间</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => format_date($result_values->established_time,"custom","Y-m-d"),
	);
			
	$form["corporate_representative"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>法人代表</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->corporate_representative,
	);
	$form["president"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>总经理</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->president,
	);
	$form["contact"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>联系人</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->contact,
	);
	$form["contact_phone"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>联系电话</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->contact_phone,
	);
	$form["contact_cellphone"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>手机</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->contact_cellphone,
	);
	$form["contact_fax"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>传真</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->contact_fax,
	);
	$form["contact_mail"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>邮箱</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->contact_mail,
	);
	$form["contact_postcode"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>邮编</th><td>",
		"#suffix" => "</td></tr>",

		"#markup" => $result_values->contact_postcode,
	);
	$form["registration_address"] = array(
		"#type" => "item",
		
		"#prefix" => "<tr><th>注册地址</th><td>",
		"#suffix" => "</td>",

		"#markup" => $result_values->registration_address,
	);
	$form["office_address"] = array(
		"#type" => "item",
		
		"#prefix" => "<th>办公地址</th><td>",
		"#suffix" => "</td></tr></table>",

		"#markup" => $result_values->office_address,
	);
		return $form;
}

function fund_manager_intro_view_form_submit($form, &$form_state){
	$form_state["redirect"] = "fund_manager_intro";
}

function fund_manager_intro_edit_form($form, &$form_state, $fund_id)
{
	$query = "SELECT * FROM {fund_manager_intro} WHERE fund_id = ?";
	$query_result = db_query($query, array($fund_id));
	$result_values = "";
	foreach ($query_result as $result_values)
	{
	}
	drupal_add_css(drupal_get_path("module","fund_basic_information")."/rkrz_form.css");
	$form["fund_manager"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<table><tr><th>基金管理人</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->fund_manager,
	);
	$form["organization_form"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>组织形式</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->organization_form,
	);
	$form["register_capital"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>注册资本</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->register_capital,
	);
	$today = getdate($result_values->established_time);
	$form["established_time"] = array(
		"#type" => "date",
		
		"#prefix" => "<th>成立时间</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => array("year"=>$today["year"],"month"=>$today["month"],"day"=>$today["mday"]),
	);
			
	$form["corporate_representative"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>法人代表</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->corporate_representative,
	);
	$form["president"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>总经理</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->president,
	);
	$form["contact"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>联系人</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->contact,
	);
	$form["contact_phone"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>联系电话</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->contact_phone,
	);
	$form["contact_cellphone"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>手机</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->contact_cellphone,
	);
	$form["contact_fax"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>传真</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->contact_fax,
	);
	$form["contact_mail"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>邮箱</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->contact_mail,
	);
	$form["contact_postcode"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>邮编</th><td>",
		"#suffix" => "</td></tr>",

		"#default_value" => $result_values->contact_postcode,
	);
	$form["registration_address"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<tr><th>注册地址</th><td>",
		"#suffix" => "</td>",

		"#default_value" => $result_values->registration_address,
	);
	$form["office_address"] = array(
		"#type" => "textfield",
		
		"#prefix" => "<th>办公地址</th><td>",
		"#suffix" => "</td></tr></table>",

		"#default_value" => $result_values->office_address,
	);
	$form["fund_id"] = array(
	"#type" => "hidden",
	"#value" => $fund_id, 
	);
	$form["submit"] = array(
		"#type" => "submit",
		"#value" => t("提交"),
	);
	return $form;
}

function fund_manager_intro_edit_form_submit($form, &$form_state){
	$values = $form_state["values"];
	$established_time_times = mktime(0,0,0,$values["established_time"]["month"],$values["established_time"]["day"],$values["established_time"]["year"]);
	
	$query = "UPDATE {fund_manager_intro} SET fund_manager=:0, organization_form=:1, register_capital=:2, established_time=:3, corporate_representative=:4, president=:5, contact=:6, contact_phone=:7, contact_cellphone=:8, contact_fax=:9, contact_mail=:10, contact_postcode=:11, registration_address=:12, office_address=:13 WHERE fund_id = :14"; 
	$args = array(
	":0"=>$values["fund_manager"],
	":1"=>$values["organization_form"],
	":2"=>$values["register_capital"],
	":3"=>$established_time_times,
	":4"=>$values["corporate_representative"],
	":5"=>$values["president"],
	":6"=>$values["contact"],
	":7"=>$values["contact_phone"],
	":8"=>$values["contact_cellphone"],
	":9"=>$values["contact_fax"],
	":10"=>$values["contact_mail"],
	":11"=>$values["contact_postcode"],
	":12"=>$values["registration_address"],
	":13"=>$values["office_address"],
	":14"=>$values["fund_id"],
	);
	db_query($query, $args);
}

function fund_manager_intro_edit_form_validate($form, &$form_state){
	if ($form_state['values']['register_capital'] <= 0) {
	    form_set_error('register_capital', '注册资本必须大于0，请确认。');
	  }
}

function shareholder_info_edit_page($id)
{
	$html = array("#markup" => "");
	$query = "SELECT id ,fund_id FROM " .
           "{shareholder_info} where id = ?";
    $queryResult = db_query($query, array($id));
	$fund_id = '';
    $ifempty =TRUE;
    foreach ($queryResult as $links ) {
	   if($links->id>0){
	   	   $ifempty = FALSE;
		   $fund_id = $links->fund_id;
	   }
    }
	if($ifempty)
	   drupal_goto('fund_basic_information/list');
	$edit_form = drupal_get_form("shareholder_info_edit_form",$id);
	$html["#markup"] .= l('返回列表','fund_manager_intro/view/'.$fund_id).'&nbsp;&nbsp;';
	$html["#markup"] .= drupal_render($edit_form);
	return $html;
}

function shareholder_info_create_page($fund_id)
{
	$html = array("#markup" => "");
	$create_form = drupal_get_form("shareholder_info_create_form",$fund_id);
	$html["#markup"] .= drupal_render($create_form);
	return $html;
}

function shareholder_info_create_form($form,&$form_state,$fund_id)
{
	$form["principal_shareholder"] = array(
		"#type" => "textfield",
		"#title" => "主要股东/合伙人",
	);
	$form["contribution_amount"] = array(
		"#type" => "textfield",
		"#title" => "出资额",
		"#default_value" => 1,
	);
	$form["brief_intro"] = array(
		"#type" => "textarea",
		"#title" => "简介",
	);
	$form["comment"] = array(
		"#type" => "textarea",
		"#title" => "备注",
	);
	$form["fund_id"] = array(
		"#type" => "hidden",
		"#value" => $fund_id,
	);
	$form["submit"] = array(
		"#type" => "submit",
		"#value" => "提交",
	);
	return $form;
}

function shareholder_info_create_form_submit($form,&$form_state)
{
	$values = $form_state["values"];
	$query = "INSERT INTO {shareholder_info} (id, fund_id, principal_shareholder, contribution_amount, brief_intro, comment) VALUES
	(null, ?, ?, ?, ?, ?)";
	$args = array($values["fund_id"],$values["principal_shareholder"], $values["contribution_amount"],
	$values["brief_intro"],$values["comment"]);
	db_query($query,$args);
	$form_state["redirect"] = "fund_manager_intro/view/".$values["fund_id"];
}

function shareholder_info_edit_form($form,&$form_state,$id)
{
	$query = "SELECT * FROM {shareholder_info} WHERE id = ?";
	$query_result = db_query($query, array($id));
	$result_values = "";
	foreach ($query_result as $result_values)
	{
	}	
	$form["principal_shareholder"] = array(
		"#type" => "textfield",
		"#title" => "主要股东/合伙人",
		"#default_value" => $result_values->principal_shareholder,
	);
	$form["contribution_amount"] = array(
		"#type" => "textfield",
		"#title" => "出资额",
		"#default_value" => $result_values->contribution_amount,
	);
	$form["brief_intro"] = array(
		"#type" => "textarea",
		"#title" => "简介",
		"#default_value" => $result_values->brief_intro,
	);
	$form["comment"] = array(
		"#type" => "textarea",
		"#title" => "备注",
		"#default_value" => $result_values->comment,
	);
	$form["id"] = array(
		"#type" => "hidden",
		"#value" => $id,
	);
	$form["back"] = array(
		"#type" => "submit",
		"#value" => "返回",
		"#submit" => array("shareholder_info_edit_form_back"),
	);
	$form["submit"] = array(
		"#type" => "submit",
		"#value" => "提交",
	);
	$form["delete"] = array(
		"#type" => "submit",
		"#value" => "删除",
		"#submit" => array("shareholder_info_edit_form_delete"),
	);
	return $form;
}

function shareholder_info_edit_form_back($form, &$form_state)
{
	$values = $form_state["values"];
	$html = array("#markup" => "");
	$query = "SELECT id ,fund_id FROM " .
           "{shareholder_info} where id = ?";
    $queryResult = db_query($query, array($values["id"]));
	$fund_id = '';
    $ifempty =TRUE;
    foreach ($queryResult as $links ) {
	   if($links->id>0){
	   	   $ifempty = FALSE;
		   $fund_id = $links->fund_id;
	   }
    }
	if($ifempty)
	   drupal_goto('fund_basic_information/list');
	$form_state["redirect"] = 'fund_manager_intro/view/'.$fund_id;
}

function shareholder_info_edit_form_submit($form, &$form_state)
{
	$values = $form_state["values"];
	$query = "UPDATE {shareholder_info} SET principal_shareholder=:0 ,contribution_amount=:1, brief_intro=:2, comment=:3 WHERE id = :4"; 
	$args = array(
	":0"=>$values["principal_shareholder"],
	":1"=>$values["contribution_amount"],
	":2"=>$values["brief_intro"],
	":3"=>$values["comment"],
	":4"=>$values["id"],
	);
	db_query($query, $args);
	$form_state["redirect"] = "fund_manager_intro";
}

function shareholder_info_edit_form_delete($form, &$form_state)
{
	$values = $form_state["values"];
	$html = array("#markup" => "");
	$query = "SELECT id ,fund_id FROM " .
           "{shareholder_info} where id = ?";
    $queryResult = db_query($query, array($values["id"]));
	$fund_id = '';
    $ifempty =TRUE;
    foreach ($queryResult as $links ) {
	   if($links->id>0){
	   	   $ifempty = FALSE;
		   $fund_id = $links->fund_id;
	   }
    }
	if($ifempty)
	   drupal_goto('fund_basic_information/list');
	$query = "DELETE FROM {shareholder_info} WHERE id = ?";
	$args = array($values["id"]);
	db_query($query, $args);
	$form_state["redirect"] = 'fund_manager_intro/view/'.$fund_id;
}

